import axios from '@/utils/axios.js';
import {
	customApiBaseURL as baseURL
} from '@/config/index.js';

/**
 * 
 */
export const callApiBySuffix = ({
	suffix,
	data = ''
}) => axios({
	method: 'post',
	data: data,
	url: '/apiaccess/api/' + suffix
})

/**
 * 登录接口
 * @param {object} [data] 发送键值对数据
 * @returns {promise}
 */
export const authLogin = (data) => axios({
	method: 'post',
	header: {
		"isToken": false
	},
	data: data,
	url: baseURL + '/metaworks/iam/app/uc/app/login'
})
/**
 * 获取xMiner数据
 * @param {object} [data] 发送键值对数据
 * @returns {promise}
 */
export const getXminerData = (data) => axios({
	method: 'post',
	header: {
		"isToken": true
	},
	data: data,
	url: baseURL + '/metaworks/dcp/data/data/v3/getByApiCode'
})



/**
 * 获取平台级隐私申明
 * @param {object} [data] 发送键值对数据
 * @returns {promise}
 */
export const authPrivacyPolicyUrl = (data) => axios({
	method: 'get',
	header: {
		"isToken": true
	},
	data: data,
	url: baseURL + '/iam/uc/v1/privacyPolicyUrl'
})

/**
 * 签署平台级隐私申明
 * @param {object} [data] 发送键值对数据
 * @returns {promise}
 */
export const authPrivacyAgreement = (data) => axios({
	method: 'post',
	header: {
		"isToken": true
	},
	data: data,
	url: baseURL + '/iam/uc/v1/privacyAgreement'
})
/**
 * 签署平台级隐私申明
 * @param {object} [data] 发送键值对数据
 * @returns {promise}
 */
export const authPrivacyAgreement1 = (data) => axios({
	method: 'get',
	header: {
		"isToken": true
	},
	data: data,
	url: baseURL + '/iam/uc/v1/tenant/privacyAgreement/lastet'
})
/**
 * 海康签名
 */
import CryptoJS from 'crypto-js'
const sign = (key, value) => {
	return CryptoJS.enc.Base64.stringify(CryptoJS.HmacSHA256(value, key))
}
const appKey = '26033163' // 访问密钥ID
const appSecret = '4NnDpBI5Gsh9HvO49JsO' // 与访问密钥ID结合使用的密钥，对请求进行加密签名
// 获取海康请求头
function getHeaders(url) {
	let sign_str = `POST\n*/*\napplication/json\nx-ca-key:${appKey}\n${url}`
	let signature = sign(appSecret, sign_str)
	let header = {
		'Accept': '*/*',
		'Content-Type': 'application/json',
		'x-ca-key': appKey,
		'x-ca-signature': signature,
		'x-ca-signature-headers': 'x-ca-key',
		"isToken": false
	}
	return header
}


let hkIp = 'https://10.16.12.253:443'
let hkiRegionsApi = '/artemis/api/resource/v1/cameras'
let hkiSubRegionsApi = '/artemis/api/resource/v1/regions/subRegions'
let hkiUrlsApi = '/artemis/api/video/v2/cameras/previewURLs'

// location /video/ {
//     proxy_pass https://192.168.122.32/;
// }

/** 
 * 获取监控区域数据
 */
export const getRegions = (data) => axios({
	method: 'post',
	header: getHeaders(hkiRegionsApi),
	data: {
		"pageNo": 1,
		"pageSize": 200
	},
	url: baseURL + hkiRegionsApi
})
/** 
 * 获取下一级监控点数据
 */
export const getSubRegions = (data) => axios({
	method: 'post',
	header: getHeaders(hkiSubRegionsApi),
	data: {
		"parentIndexCode": "root000000",
		"resourceType": "camera",
		"pageNo": 1,
		"pageSize": 100,
		"cascadeFlag": 0
	},
	url: baseURL + hkiSubRegionsApi
})
/** 
 * 获取播放url数据
 */
export const getURLS = (data) => axios({
	method: 'post',
	header: getHeaders(hkiUrlsApi),
	data: data,
	url: hkIp + hkiUrlsApi
})
